package com.binest.invitationLink.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.invitationLink.domain.InvitationLink;
import com.binest.invitationLink.service.IInvitationLinkService;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * 邀请链接Controller
 *
 * @author wwd
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/invitationLink")
public class InvitationLinkController extends BaseController {
    @Autowired
    private IInvitationLinkService invitationLinkService;

    /**
     * 查询邀请链接列表
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvitationLink invitationLink) {
        startPage();
        List<InvitationLink> list = invitationLinkService.selectInvitationLinkList(invitationLink);
        return getDataTable(list);
    }

    /**
     * 导出邀请链接列表
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:export')")
    @Log(title = "邀请链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvitationLink invitationLink) {
        List<InvitationLink> list = invitationLinkService.selectInvitationLinkList(invitationLink);
        ExcelUtil<InvitationLink> util = new ExcelUtil<InvitationLink>(InvitationLink.class);
        util.exportExcel(response, list, "邀请链接数据");
    }

    /**
     * 获取邀请链接详细信息
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:query')")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(String id) {
        return success(invitationLinkService.selectInvitationLinkById(id));
    }

    /**
     * 新增邀请链接
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:add')")
    @Log(title = "邀请链接", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InvitationLink invitationLink) {
        return toAjax(invitationLinkService.insertInvitationLink(invitationLink));
    }

    /**
     * 修改邀请链接
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:edit')")
    @Log(title = "邀请链接", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody InvitationLink invitationLink) {
        return toAjax(invitationLinkService.updateInvitationLink(invitationLink));
    }


    @PostMapping("/update")
    public AjaxResult update(@RequestBody InvitationLink invitationLink) {
        return toAjax(invitationLinkService.updateLink(invitationLink));
    }

    /**
     * 删除邀请链接
     */
//    @PreAuthorize("@ss.hasPermi('invitationLink:invitationLink:remove')")
    @Log(title = "邀请链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(invitationLinkService.deleteInvitationLinkByIds(ids));
    }

    /**
     * 获取本人的邀请链接
     *
     * @param
     * @return
     */
    @GetMapping("/getLink")
    public AjaxResult getLink() {
            return success(invitationLinkService.selectInvitationLinkByCreateBy());
        }



}
